<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Origami::Graphics::Color</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Origami::Graphics::Color</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/origami/graphics/colors_rb.html">
                origami/graphics/colors.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000050">to_a</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Color/Space.html" class="link">Origami::Graphics::Color::Space</a><br />
Class <a href="Color/CMYK.html" class="link">Origami::Graphics::Color::CMYK</a><br />
Class <a href="Color/GrayScale.html" class="link">Origami::Graphics::Color::GrayScale</a><br />
Class <a href="Color/RGB.html" class="link">Origami::Graphics::Color::RGB</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000050" class="method-detail">
        <a name="M000050"></a>

        <div class="method-heading">
          <a href="#M000050" class="method-signature">
          <span class="method-name">to_a</span><span class="method-args">(color)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000050-source">
<pre>
     <span class="ruby-comment cmt"># File origami/graphics/colors.rb, line 91</span>
 91:       <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Color</span>.<span class="ruby-identifier">to_a</span>(<span class="ruby-identifier">color</span>)
 92:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">color</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Array</span>)
 93:         
 94:         <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:r</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:g</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:b</span>) 
 95:           <span class="ruby-identifier">r</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:r</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">r</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">255</span>
 96:           <span class="ruby-identifier">g</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:g</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">g</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">1</span>]).<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">255</span>
 97:           <span class="ruby-identifier">b</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:b</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">b</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">2</span>]).<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">255</span>
 98:           <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">r</span>, <span class="ruby-identifier">g</span>, <span class="ruby-identifier">b</span>]
 99: 
100:         <span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:c</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:m</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:y</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span> <span class="ruby-identifier">:k</span>)
101:           <span class="ruby-identifier">c</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:c</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">c</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">0</span>]).<span class="ruby-identifier">to_f</span>
102:           <span class="ruby-identifier">m</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:m</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">m</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">1</span>]).<span class="ruby-identifier">to_f</span>
103:           <span class="ruby-identifier">y</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:y</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">y</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">2</span>]).<span class="ruby-identifier">to_f</span>
104:           <span class="ruby-identifier">k</span> = (<span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:k</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">k</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>[<span class="ruby-value">3</span>]).<span class="ruby-identifier">to_f</span>
105:           <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">c</span>,<span class="ruby-identifier">m</span>,<span class="ruby-identifier">y</span>,<span class="ruby-identifier">k</span>]
106:           
107:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span><span class="ruby-identifier">:g</span> <span class="ruby-keyword kw">or</span> (<span class="ruby-value">0</span><span class="ruby-value">.0</span><span class="ruby-operator">..</span><span class="ruby-value">1.0</span>) <span class="ruby-operator">===</span> <span class="ruby-identifier">color</span> 
108:           <span class="ruby-identifier">g</span> = <span class="ruby-identifier">color</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:g</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">color</span>.<span class="ruby-identifier">g</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">color</span>
109:           <span class="ruby-keyword kw">return</span> [ <span class="ruby-identifier">g</span> ]
110: 
111:         <span class="ruby-keyword kw">else</span>
112:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;Invalid color : #{color}&quot;</span>
113:         <span class="ruby-keyword kw">end</span>
114:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>